package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.DictMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.util.resources.cldr.it.CalendarData_it_CH;

import java.util.ArrayList;
import java.util.List;

/*==================================
      时 间:   2023-03-18
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
===================================*/
public class DictListener  extends AnalysisEventListener<DictEeVo> {

   private DictMapper dictMapper;


    public DictListener(DictMapper dictMapper){
        this.dictMapper=dictMapper;
    }

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict=new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);

        Dict dict1 = dictMapper.selectById(dict.getId());
        if(dict1 == null){
            this.dictMapper.insert(dict);
        }else{
            this.dictMapper.updateById(dict);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
